<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:with="title='评论管理',active='comment'">
<header th:replace="back/header::headerFragment(${title},${active})"></header>
<head>
    <meta th:name="_csrf" th:content="${_csrf.token}"/>
    <meta th:name="_csrf_header" th:content="${_csrf.headerName}"/>
    <style>
        .comment-list-card {
            background: #fff;
            border-radius: 14px;
            box-shadow: 0 4px 24px rgba(60,60,60,0.08);
            padding: 32px 28px 24px 28px;
            margin-top: 24px;
            margin-bottom: 24px;
        }
        .comment-list-title {
            display: flex;
            align-items: center;
            font-size: 26px;
            font-weight: 600;
            color: #4a4a4a;
            background: linear-gradient(90deg,#f5f7fa 60%,#e3e6ec 100%);
            border-radius: 12px 12px 0 0;
            box-shadow: 0 2px 8px #e3e6ec;
            padding: 18px 24px 14px 18px;
            margin-bottom: 0;
        }
        .comment-list-title i {
            color: #8662c6;
            font-size: 30px;
            margin-right: 16px;
        }
        .table-comment {
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0 2px 8px #e3e6ec;
            margin-bottom: 0;
        }
        .table-comment thead th {
            background: #f5f5f5;
            color: #333;
            font-weight: 600;
            border-bottom: 2px solid #e0e0e0;
        }
        .table-comment tbody tr:hover {
            background: #f0f4ff;
            transition: background 0.2s;
        }
        .table-comment td, .table-comment th {
            vertical-align: middle !important;
        }
        .table-comment td {
            font-size: 16px;
        }
        .btn {
            border-radius: 8px !important;
            font-size: 15px;
            box-shadow: 0 1px 4px #e3e6ec;
            transition: background 0.2s, box-shadow 0.2s;
        }
        .btn-primary {
            background: linear-gradient(90deg,#8662c6 60%,#a084e8 100%) !important;
            border: none !important;
        }
        .btn-primary:hover {
            background: linear-gradient(90deg,#a084e8 60%,#8662c6 100%) !important;
            box-shadow: 0 4px 16px #b39ddb;
        }
        .btn-danger {
            background: linear-gradient(90deg,#ff5252 60%,#ff867f 100%) !important;
            border: none !important;
        }
        .btn-danger:hover {
            background: linear-gradient(90deg,#ff867f 60%,#ff5252 100%) !important;
            box-shadow: 0 4px 16px #ffb3b3;
        }
        .btn-warning {
            background: linear-gradient(90deg,#ffd740 60%,#ffe57f 100%) !important;
            border: none !important;
            color: #333 !important;
        }
        .btn-warning:hover {
            background: linear-gradient(90deg,#ffe57f 60%,#ffd740 100%) !important;
            box-shadow: 0 4px 16px #fff9c4;
            color: #333 !important;
        }
        .m-b-5 {
            margin-bottom: 5px !important;
        }
        .paging-area {
            margin-top: 30px;
        }
    </style>
</head>
<body class="fixed-left">
<div id="wrapper">
    <div th:replace="back/header::header-body"></div>
    <div class="content-page">
        <div class="content">
            <div class="container">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="comment-list-title">
                            <i class="fa fa-comments"></i>
                            <span>评论管理</span>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="comment-list-card">
                            <table class="table table-striped table-bordered table-comment">
                                <thead>
                                <tr>
                                    <th>作者</th>
                                    <th>评论时间</th>
                                    <th>文章标题</th>
                                    <th>评论内容</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <th:block th:each="comment : ${comments.list}">
                                    <tr th:id="${comment.id}">
                                        <td th:text="${comment.author}"></td>
                                        <td th:text="${#dates.format(comment.created, 'yyyy-MM-dd HH:mm')}"></td>
                                        <td>
                                            <a th:href="@{'/article/'+${comment.articleId}}" th:text="${comment.articleTitle}" target="_blank"></a>
                                        </td>
                                        <td th:text="${comment.content}"></td>
                                        <td>
                                            <span th:if="${comment.status} == 'approved'" style="color:green;">显示</span>
                                            <span th:if="${comment.status} != 'approved'" style="color:gray;">隐藏</span>
                                        </td>
                                        <td>
                                            <a href="javascript:void(0)" th:onclick="'deleteComment('+${comment.id}+');'" class="btn btn-danger btn-sm m-b-5">
                                                <i class="fa fa-trash-o"></i> 删除</a>
                                            <a href="javascript:void(0)" th:if="${comment.status} == 'approved'"
                                               th:attr="onclick=|updateStatus(${comment.id},'forbid')|"
                                               class="btn btn-warning btn-sm m-b-5">
                                                <i class="fa fa-eye-slash"></i> 隐藏</a>
                                            <a href="javascript:void(0)" th:if="${comment.status} != 'approved'"
                                               th:attr="onclick=|updateStatus(${comment.id},'approved')|"
                                               class="btn btn-primary btn-sm m-b-5">
                                                <i class="fa fa-eye"></i> 显示</a>
                                        </td>
                                    </tr>
                                </th:block>
                                </tbody>
                            </table>
                            <div class="paging-area" th:replace="comm/paging :: pageAdminNav(${comments})"></div>
                        </div>
                    </div>
                </div>
                <div th:replace="back/footer :: footer-content"></div>
            </div>
        </div>
    </div>
</div>
<div th:replace="back/footer :: footer"></div>
<script>
    function getCsrf() {
        var token = document.querySelector('meta[name="_csrf"]').getAttribute('content');
        var header = document.querySelector('meta[name="_csrf_header"]').getAttribute('content');
        return {header, token};
    }
    function deleteComment(id) {
        if(confirm('确定要删除该评论吗？')){
            var csrf = getCsrf();
            fetch('/admin/comment/delete', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                    [csrf.header]: csrf.token
                },
                body: 'id=' + id
            }).then(res => res.text()).then(data => { location.reload(); });
        }
    }
    function updateStatus(id, status) {
        var csrf = getCsrf();
        fetch('/admin/comment/status', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                [csrf.header]: csrf.token
            },
            body: 'id=' + id + '&status=' + status
        }).then(res => res.text()).then(data => { location.reload(); });
    }
</script>
</body>
</html> 